package javafx.demo.pane;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class TestAnchorPane extends Application {

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) {
		stage.setTitle("TitledPane");
		Scene scene = new Scene(new VBox(), 400, 350);
		scene.setFill(Color.GHOSTWHITE);

		AnchorPane anchorpane = new AnchorPane();
		Button buttonSave = new Button("Save");
		Button buttonCancel = new Button("Cancel");

		HBox hbox = new HBox();
		hbox.setPadding(new Insets(0, 10, 10, 10));
		hbox.setSpacing(10);
		hbox.getChildren().addAll(buttonSave, buttonCancel);

		AnchorPane.setBottomAnchor(hbox, 8.0);
		AnchorPane.setRightAnchor(hbox, 5.0);
		
		GridPane grid = new GridPane();
		grid.setHgap(10);
		grid.setVgap(10);
		grid.setPadding(new Insets(0, 0, 0, 10));

		// Category in column 2, row 1
		Text category = new Text("Sales:");
		category.setFont(Font.font("Tahoma", FontWeight.BOLD, 20));
		grid.add(category, 1, 0); 

		// Title in column 3, row 1
		Text chartTitle = new Text("Current Year");
		chartTitle.setFont(Font.font("Tahoma", FontWeight.BOLD, 20));
		grid.add(chartTitle, 2, 0);

		// Subtitle in columns 2-3, row 2
		Text chartSubtitle = new Text("Goods and Services");
		grid.add(chartSubtitle, 1, 1, 2, 1);

		// House icon in column 1, rows 1-2
		ImageView imageHouse = new ImageView(
		    new Image(TestGridPane.class.getResourceAsStream("../../image/accept_page.png")));
		grid.add(imageHouse, 0, 0, 1, 2); 

		// Left label in column 1 (bottom), row 3
		Text goodsPercent = new Text("Goods\n80%");
		GridPane.setValignment(goodsPercent, VPos.BOTTOM);
		grid.add(goodsPercent, 0, 2); 

		// Chart in columns 2-3, row 3
		ImageView imageChart = new ImageView(
		    new Image(TestGridPane.class.getResourceAsStream("../../image/add_to_folder.png")));
		grid.add(imageChart, 1, 2, 2, 1); 

		// Right label in column 4 (top), row 3
		Text servicesPercent = new Text("Services\n20%");
		GridPane.setValignment(servicesPercent, VPos.TOP);
		grid.add(servicesPercent, 3, 2);
		
		AnchorPane.setTopAnchor(grid, 10.0);

		anchorpane.getChildren().addAll(grid,hbox);   // Add grid from Example 1-5
		
		BorderPane border = new BorderPane();
		border.setLeft(anchorpane);

		VBox root = (VBox) scene.getRoot();
		root.getChildren().addAll(border);
		stage.setScene(scene);
		stage.show();
	}

}